package cate.common.table.activity.puzzle.base;

import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

@EExcelRowClass
public class PuzzleBaseRow extends ERow {
    @EExcelNoteField(fieldName = "配置id")
    public int configId;

    @NoteField("掉落列表")
    public Map<Integer, PuzzleDropConfig> dropConfigs;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        if (dropConfigs == null) {
            dropConfigs = new HashMap<>();
        }
        dropConfigs.clear();
        for (int i = 1; i <= 10; i++) {
            String fi = "掉落时间" + i;
            String fd = "掉落道具" + i;
            Integer interval = xrw.getInteger(fi);
            if (interval == null) {
                break;
            }
            String rewardStr = xrw.getString(fd);
            dropConfigs.put(i, PuzzleDropConfig.of(interval, rewardStr));
        }
    }

    public static class PuzzleDropConfig {
        public int dropInterval;
        public String dropRewardStr;

        public static PuzzleDropConfig of(int dropInterval, String dropRewardStr) {
            PuzzleDropConfig pdc = new PuzzleDropConfig();
            pdc.dropInterval = dropInterval;
            pdc.dropRewardStr = dropRewardStr;
            return pdc;
        }
    }
}
